from moviepy.editor import VideoFileClip, AudioFileClip

# 读取视频和音轨
video_clip = VideoFileClip('video.mp4')  # 替换为您的视频文件
audio_clip = AudioFileClip('audio.mp3')  # 替换为您的音轨文件

# 将音轨添加到视频
video_clip = video_clip.set_audio(audio_clip)

# 保存合并后的视频
output_video_path = 'output_video.mp4'
video_clip.write_videofile(output_video_path, codec='libx264')

# 关闭视频和音轨文件
video_clip.close()
audio_clip.close()

print(f"已将音轨成功合并到视频并保存为 {output_video_path}")
